package com.blog.controller.user;

import com.blog.dto.PageDTO;
import com.blog.result.Result;
import com.blog.service.ArticleService;
import com.blog.vo.ArticleVO;
import com.blog.vo.CategoryVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("userArticleController")
@RequestMapping("/user/article")
@Slf4j
public class ArticleController {

    @Autowired
    private ArticleService articleService;


    @PostMapping("/articleList")
    public Result<List<ArticleVO>> articleList(@RequestBody PageDTO pageDTO) {
        log.info("分页查询所有文章列表....{}",pageDTO);
        List<ArticleVO> list = articleService.userPageArticleList(pageDTO);
        return Result.success(list);
    }

    @GetMapping("/oneArticleById/{aid}")
    public Result<ArticleVO> oneArticleById(@PathVariable("aid") Long aid) {
        log.info("根据文章ID：{}，查询文章列表....",aid);
        ArticleVO articleVO = articleService.oneArticleById(aid);
        return Result.success(articleVO);
    }

    @GetMapping("/CategoryByArticleId/{aid}")
    public Result<List<CategoryVO>> CategoryByArticleId(@PathVariable("aid") Long aid) {
        log.info("根据文章ID：{}，查询文章类别....",aid);
        List<CategoryVO> categoryVOList = articleService.getCategoryByArticleID(aid);
        return Result.success(categoryVOList);
    }

    @GetMapping("/recommendArticleList/{uid}")
    public Result<List<ArticleVO>> recommendArticleList(@PathVariable("uid") Long uid) {
        log.info("查询推荐文章列表....{}",uid);
        List<ArticleVO> list = articleService.recommendArticleList(uid);
        return Result.success(list);
    }

    @GetMapping("/timeNewArticleList/{uid}")
    public Result<List<ArticleVO>> timeNewArticleList(@PathVariable("uid") Long uid) {
        log.info("查询最新发布的五篇文章列表....{}",uid);
        List<ArticleVO> list = articleService.timeNewArticleList(uid);
        return Result.success(list);
    }

    @GetMapping("/totalArticle/{uid}")
    public Result totalArticle(@PathVariable("uid") Long uid) {
        log.info("查询用户：{}，文章的总数文章列表....",uid);
        Long total = articleService.userTotalArticle(uid);
        return Result.success(total);
    }

}
